<template>
	<view style="height: 100vh; background-color: #FFFFFF;">
		 <u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true" title="演练通知"
		></u-navbar>
		<u-form ref="drillForm" :model="drillForm" label-width="140px" class="wrap">
			<u-form-item label="主体名称" prop="enterpriseName" v-if="hiddenButton">
				<u-input type="select" :select-open="enterpriseShow" placeholder="请选择主体" v-model="drillForm.enterpriseName"
					@click="enterpriseShow=true"></u-input>
			</u-form-item>
			<u-form-item label="区域名称" prop="regionName">
				<u-input type="select" :select-open="regionShow" placeholder="请选择区域" v-model="drillForm.regionName"
					@click="regionShow=true"></u-input>
			</u-form-item>
			<u-form-item label="是否联动周边力量">
				<u-radio-group v-model="drillForm.zbll" placement="row">
					<u-radio name=1 activeColor="green">是</u-radio>
					<u-radio name=0 activeColor="red">否</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="是否联动警务站">
				<u-radio-group v-model="drillForm.jwz" placement="row">
					<u-radio name=1 activeColor="green">是</u-radio>
					<u-radio name=0 activeColor="red">否</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="是否联动消防力量">
				<u-radio-group v-model="drillForm.glbm" placement="row">
					<u-radio name=1 activeColor="green">是</u-radio>
					<u-radio name=0 activeColor="red">否</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label-position="left" label="详细地址" prop="loaction">
				<u-input type="text" placeholder="请输入详情地址" v-model="drillForm.location" />
			</u-form-item>
		</u-form>
		<u-select :default-value="defaultValue" mode="mutil-column-auto" :list="regionList" value-name="ucId"
			label-name="name" v-model="regionShow" @confirm="regionConfirm"></u-select>
			
			<u-select :default-value="enterpriseIdDefaultValue" mode="mutil-column-auto" :list="enterpriseList" value-name="ucId"
				label-name="name" v-model="enterpriseShow" @confirm="enterpriseConfirm"></u-select>
		<u-button @click="submit" type="error" style="margin: 24rpx;">发送通知</u-button>
	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				drillForm: {
					zbll: 0,
					jwz: 0,
					glbm: 0,
					regionId: '',
					location: ''
				},
				show: false,
				regionShow: false,
				enterpriseShow:false,
				regionList: [],
				enterpriseList:[],
				defaultValue: [],
				enterpriseIdDefaultValue:[],
				enterpriseId:null,
				rules: {
					regionName: [{
						required: true,
						message: '请选择区域',
						trigger: ['change', 'blur'],
					}],
				},
				roleCode:"",
				hiddenButton:false,
			}
		},
		onLoad(e) {
			
			let userInfo = JSON.parse(this.utils.getStorageSync("userInfo"))
			
			if(userInfo.roleCode=="XFZD-ADMIN"||userInfo.roleCode=="XT-ADMIN"||userInfo.roleCode=="ZD-ADMIN"||userInfo.roleCode=="DD-ADMIN"||userInfo.roleCode=="JW-ADMIN"){
				this.hiddenButton=true
			}
		},
		onShow() {
			this.initView()
		},
		onReady(e) {
			this.$refs.drillForm.setRules(this.rules)
		},
		methods: {
			initView() {
				this.getInRegionList()
				this.getEnterpriseList()				
			},
			getInRegionList() {
				this.utils.request("/api/app/region/getSubfieldRegionList", {
					enterpriseId:this.enterpriseId
				}, "post", "app", true).then(res => {
					this.regionList = res.data
				}).catch(error => {
					console.log(error)
				})
			},
			getEnterpriseList() {
				this.utils.request("/api/app/enterpriseDominant/getEnterpriseList", {
					deleted: false,
				}, "post", "app", true).then(res => {
					this.enterpriseList = res.data
				}).catch(error => {
					console.log(error)
				})
			},
			regionConfirm(e) {
				e.map((val, index) => {
					this.drillForm.regionName = val.label
					this.drillForm.ucId = val.value
				})
			},
			enterpriseConfirm(e){
				this.drillForm.regionId =null
				this.drillForm.regionName =null
				e.map((val, index) => {
					this.drillForm.enterpriseName = val.label
					this.drillForm.enterpriseId = val.value
					if(this.hiddenButton){
						this.enterpriseId=val.value
						this.getInRegionList()
					}
				})

			},
			submit() {
				let that = this
				that.$refs.drillForm.validate(valid => {
					if (valid) {
						that.drillForm.zbll = parseInt(that.drillForm.zbll)
						that.drillForm.jwz = parseInt(that.drillForm.jwz)
						that.drillForm.glbm = parseInt(that.drillForm.glbm)
						that.utils.request("/api/app/fireInfo/drillNotice", that.drillForm,
							"post", "app", true).then(res => {
						    that.utils.goHome() 
						}).catch(error => {
							uni.showToast({
							    title: error.msg,
							    duration: 1000,
								icon:"none",
							});	
						})
					} else {
						console.log("验证失败")
					}
				})
			},

		}
	}
</script>

<style>

</style>
